package com.xxx.management.web.controller;


import com.xxx.common.base.bo.ListResult;
import com.xxx.management.web.util.R;
import com.xxx.user.api.UserApi;
import com.xxx.user.dto.*;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.openfeign.SpringQueryMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@Slf4j
@RestController
@AllArgsConstructor
public class UserController {

    private final UserApi userApi;

    /**
     * 用户创建
     */
    @PostMapping("/v2/user/create")
    public R<String> create(@RequestBody UserCreateReqDTO param) {
        return R.ok(userApi.create(param));
    }

    /**
     * 用户更新
     */
    @PutMapping("/v1/user/update")
    public R<String> update(@RequestBody UserUpdateReqDTO param) {
        return R.ok(userApi.update(param));
    }

    /**
     * 用户删除
     */
    @DeleteMapping("/v1/user/delete")
    public R<String> delete(@RequestBody List<Long> ids) {
        return R.ok(userApi.delete(ids));
    }

    /**
     * 获取用户数据
     */
    @GetMapping("/v1/user/getAll")
    public R<ListResult<UserGetAllResDTO>> getAll(@SpringQueryMap UserGetAllReqDTO param) {
        return R.ok(userApi.getAll(param));
    }

    /**
     * 用户登录
     */
    @PostMapping("/v2/user/login")
    public R<String> login(@RequestBody UserDoLoginReqDTO param) {
        return R.ok(userApi.login(param));
    }

}
